package com.edu.backend.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: yanjunfeng
 * @Description: TODO
 * @Date: Created in 下午3:47 2023/6/12
 * @Modified By:
 */
//@Configuration
public class MyMVCConfig implements WebMvcConfigurer {

    @Autowired
    LoginInterceptor loginInterceptor;
    /**
     * 注册拦截器
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)//注册拦截器
        .addPathPatterns("/**")  //拦截所有请求
        .excludePathPatterns("/login"); //过滤拦截白名单
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("file:D:\\桌面\\qndxxz-master\\src\\assets\\img");
    }




    /**
     * 解决跨域请求
     * @param registry
     */
//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        registry.addMapping("/**")
//                //是否发送cookie
//                .allowCredentials(true)
//                //放行哪些原始域
//                //.allowedOrigins("*")
//                .allowedOriginPatterns("*")
//                //放行哪些请求方法
//                .allowedMethods("GET", "POST", "PUT", "DELETE")
//                //放行哪些请求头信息
//                .allowedHeaders("*")
//                //暴露哪些请求头信息
//                .exposedHeaders("*");
//    }
}